package com.example.mscloud.controller;

import com.example.mscloud.common.entities.Payment;
import com.example.mscloud.common.entities.result.CommonResult;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;

@RestController
public class OrderController {

    @Resource
    private RestTemplate restTemplate;

    private final String PAYMENT_URL = "http://cloud-payment-service/";

    @GetMapping("order/payment/create")
    public CommonResult<Payment> paymentCreate(Payment payment){
        return restTemplate.postForObject(PAYMENT_URL + "payment/create", payment, CommonResult.class);
    }


    @GetMapping("order/payment/info/{id}")
    public CommonResult<Payment> paymentInfo(@PathVariable("id") Long id){
        return restTemplate.getForObject(PAYMENT_URL + "payment/info/"+id, CommonResult.class);
    }

    @GetMapping("heartbeat")
    public CommonResult heartbeat(){
        return restTemplate.getForObject(PAYMENT_URL + "payment/heartbeat", CommonResult.class);
    }
}
